<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script src="${base}/js/crytojs/components/core.js"></script>
<script src="${base}/js/crytojs/components/md5.js"></script>
<script src="${base}/js/crytojs/components/evpkdf.js"></script>
<script src="${base}/js/crytojs/components/enc-base64.js"></script>
<script src="${base}/js/crytojs/components/cipher-core.js"></script>
<script src="${base}/js/crytojs/components/aes.js"></script>
<script src="${base}/js/crytojs/components/mode-ecb.js"></script>


<script type="text/javascript">

var aesEncrypt = CryptoJS.AES.encrypt("这是原文abc", "Secret Passphrase");
console.log("简单加密aesEncrypt = %s", aesEncrypt.iv.toString(CryptoJS.enc.Hex));

var aesDecrypt = CryptoJS.AES.decrypt(aesEncrypt, "Secret Passphrase");
console.log("简单解密aesDecrypt = %s", aesDecrypt.toString(CryptoJS.enc.Utf8));
</script>






<script type="text/javascript">


var key ="1234567812345678";
var iv = "1234567812345678";

function encrypt(text){
    return CryptoJS.AES.encrypt(text,CryptoJS.enc.Utf8.parse(key),{
        iv:CryptoJS.enc.Utf8.parse(iv),
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.Pkcs7
    })
}
 
function decrypt(text){
    var result = CryptoJS.AES.decrypt(text,CryptoJS.enc.Utf8.parse(key),{
        iv:CryptoJS.enc.Utf8.parse(iv),
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.Pkcs7
    })
    return result.toString(CryptoJS.enc.Utf8)
}


function test() {
	var source = $("#source").val();
	var cc = encrypt(source);
	$("#target").val(cc);
}

function test1() {
	var source = $("#sourceS").val();
	var dd = decrypt(source);
	$("#jiemi").val(dd);
}


</script>



<body>
    <h1>F12请看console</h1>
 	<div>
		原文:<textarea id="source" value="" style="width: 500px; height: 90px;" /></textarea>
		<hr>
		密文:<textarea id="target" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		<input type="button" onclick="test();" name="" value="加密" />
		<hr>
		密文: <textarea id="sourceS" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		原文: <textarea id="jiemi" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		<input type="button" onclick="test1();" name="" value="解密" />
	</div>
</body>
</html>
